using System.Globalization;
using Microsoft.Maui.Controls;

namespace demo001
{
    /// <summary>
    /// 将布尔值转换为图像资源的转换器
    /// 用于密码显示/隐藏图标切换
    /// </summary>
    public class BoolToImageSourceConverter : IValueConverter
    {
        /// <summary>
        /// 将布尔值转换为对应的图像资源
        /// </summary>
        /// <param name="value">布尔值，表示密码是否隐藏</param>
        /// <param name="targetType">目标类型</param>
        /// <param name="parameter">附加参数</param>
        /// <param name="culture">文化信息</param>
        /// <returns>对应的图像资源</returns>
        public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            if (value is bool isHidden)
            {
                // 根据密码是否隐藏返回对应的图标
                return isHidden ? "eyeclose.png" : "eyeopen.png";
            }
            
            // 默认返回闭眼图标
            return "eyeclose.png";
        }

        /// <summary>
        /// 反向转换（本转换器不需要实现此方法）
        /// </summary>
        public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}